473,418 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Sorting in C#

How do you sort in C# programmatically.
Meaning not to use the properties window to set sort to true.
Meaning not to use Array.Sort feature either.
This is actually a sort array coded programmatically at runtime.

Thanks i appreciate for your help.
Nov 17 '09 #1

✓ answered by cloud255

Sorting is based on algorithms, its not really language specific. Several of the .NET collections have sorting methods already exposed. For us to help you with a sorting algorithm you need to be more specific. What datastructure are you trying to sort? Is there any specific sorting technique you would like to use?

Have a look at Insertion sort, Selection sort, Bubble sort and Quick sort These are all fairly well known and easy to implement algorithms.

8 2996
Plater
7,872 Expert 4TB
You want to create your own sorting implementation? There's going to be thosaunds of websites that detail the algorithms. Try googling for some.
Nov 17 '09 #2
I did and got this site. This site actually stated that I can get help in programming. I just needed some help. So here I am asking. Can anyone in this forum help me in sorting in C#.

Thanks.
Nov 18 '09 #3
cloud255
427 Expert 256MB
Sorting is based on algorithms, its not really language specific. Several of the .NET collections have sorting methods already exposed. For us to help you with a sorting algorithm you need to be more specific. What datastructure are you trying to sort? Is there any specific sorting technique you would like to use?

Have a look at Insertion sort, Selection sort, Bubble sort and Quick sort These are all fairly well known and easy to implement algorithms.
Nov 18 '09 #4
Plater
7,872 Expert 4TB
I didn't mean for it to sound like I was giving you the "runaround".
Your question wasn't very clear. You never actually said "I am trying to implement my own sorting functions, but am not sure how to start"
Cloud went a step further then me and did some leg work for you, finding links to common sorting algorithms, which is what I was trying to get at by suggesting to google it.
We will not write your sorting function for you, but we can help you if you're stuck in your implementation.
Nov 18 '09 #5
Hello Cloud and Plater,

My bad I forgot to say that.
I am trying to have the contents of a textbox displayed in the listbox sorted by lastname and alphabetically. I know about the feature in properties but they want it to be done programmatically. I am not sure how to go about it. But I know its an array that I need to sort. The feature in the .Net Framework is Array.Sort. Now in order to be valid it has to be done programmatically.

I also previously posted my entire code for the AddressBook array. I cannot get it to work accordingly.

Can you help me.
Nov 18 '09 #6
Plater
7,872 Expert 4TB
Well i would consider Array.Sort() to be programmatically, chances are pretty good that's what was meant. Just not having to sort it by hand.

If you want to use array.sort(), you will probably have to deal with either ICompare interface or the IComparable interface (depending on how you want to tackle it) The basic idea is to provide a function that takes in two different objects of the same type and you return either a -1,0,1 to say if object A comes before, is the same, or after object b.
You would have access to all of A and Bs values, so you can compare by last name then sort by first name.
Nov 19 '09 #7
Curtis Rutland
3,256 Expert 2GB
Is this a schoolwork assignment? If so, read up on the links that cloud provided, and implement one of those algorithms.

If not, then the Array.Sort() method is perfect. If you need custom sorting, I prefer to use the IComparable interface.
Nov 19 '09 #8
Hello inSertAlias,

Yes I agree I wish I could use the Array.Sort is much better and easier.
I have to study a little more on the sort you mentioned that Cloud pointed out for me. Ok thanks all.

I'll try my best to do this final assignment. Been working on it for a week and is due next Tuesday but thanks all and I understand. Thanks

Regards,

Desi Bravo
Nov 20 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.